package com.zdy.boot.upload.domain;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.digest.MD5;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.File;

/**
 * @author sdy
 * @description
 * @date 2025/2/9
 */
@Slf4j
@Data
public class VideoEntity {

    private String originFileName;
    private String fileName;
    private String content;
    private String checkMd5;
    private int part;
    private boolean ifEnd;
    private long fileSize;

    public VideoEntity(String fileName, int partNum, byte[] content, boolean isEnd) {
        this.originFileName = fileName;
        this.fileName = fileName + ".part_" + partNum;
        this.content = Base64.encode(content);
        this.checkMd5 = MD5.create().digestHex(content);
        this.part = partNum;
        this.ifEnd = isEnd;
        this.fileSize = content.length;
    }

    public VideoEntity(File file) {
        this.originFileName = file.getName();
        this.fileName = file.getName();
        this.content = Base64.encode(file);
        this.checkMd5 = MD5.create().digestHex(content);
        this.part = 1;
        this.ifEnd = true;
        this.fileSize = file.length();
    }

}
